package com.ggh.jinjilive.ui.mine.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemAddressBinding;
import com.ggh.jinjilive.databinding.ItemDiamondBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;
import com.ggh.jinjilive.mobile.mine.DiamondMobile;

import java.util.List;

public class DiamondAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<DiamondMobile> diamondMobileList;

    public void setAdd(List<DiamondMobile> diamondMobileList) {
        this.diamondMobileList = diamondMobileList;
        notifyDataSetChanged();
    }


    private AddItemOnClickListener addItemOnClickListener;
    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemDiamondBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_diamond, parent, false);
        return new ItemViewHolder(binding);
    }

    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder recyclerViewholder,final int position) {
        DiamondMobile diamondMobile = diamondMobileList.get(position);
        ItemViewHolder holder = (ItemViewHolder) recyclerViewholder;
        if(null != diamondMobile){
            holder.binding.mineMydiamondTitle.setText(diamondMobile.getTitle());
            holder.binding.mineMydiamondDesc.setText(diamondMobile.getDesc());
            holder.binding.mineMydiamondPrice.setText(diamondMobile.getPrice());
            holder.binding.llDiamond.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(null != addItemOnClickListener){
                        addItemOnClickListener.onSkipClicked(position,diamondMobile);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return null == diamondMobileList ? 0 : diamondMobileList.size();
    }


    class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemDiamondBinding binding;
        public ItemViewHolder(@NonNull ItemDiamondBinding binding) {
            super(binding.getRoot());
            this.binding = binding;

        }
    }

}